package com.wxd.modules.job.task;

import com.wxd.annotation.SysLog;
import com.wxd.modules.sys.service.SysLogService;
import com.wxd.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *
 * testTask为spring bean的名称
 *
 */
@Component("deleteLogTask")
public class deleteLogTask implements ITask {
    @Autowired
    private SysLogService sysLogService;
    private Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * 定时清除timeTaskLog n天之前的记录
     */
    @SysLog("定时删除几天的系统日志")
    @Override
    public void run(String params) {
        logger.info("【定时清除timeTaskLog n天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>开始执行");
        Date currentDate = new Date();
        int day =Integer.valueOf(params);
        Date deleteDate = DateUtil.nextDay(currentDate, day);
        int ret =sysLogService.deleteLog(deleteDate);
        if(ret >0){
            logger.info("【定时清除timeTaskLog" +day+"天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行成功");
        }else{
            logger.info("【定时清除timeTaskLog" +day+"天之前的记录】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行失败");
        }
    }
}